package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfResourceWhitelist;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.service.ConfResourceWhitelistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务资源白名单配置表-Controller
 * @author zfsn
 * @date 2023-3-28
 */
@Api(tags = "业务服务资源管理-黑白名单配置-白名单")
@RestController
@RequestMapping("/resourceWhitelist")
public class ConfResourceWhitelistController {

	@Autowired
	private ConfResourceWhitelistService confResourceWhitelistService;

	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{ids}")
	public R<List<ConfResourceWhitelist>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confResourceWhitelistService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param confResourceWhitelist 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	public R<Page<ConfResourceWhitelist>> listPage(@RequestBody ConfResourceWhitelist confResourceWhitelist) {
		return R.ok(confResourceWhitelistService.listPage(confResourceWhitelist));
	}

	/**
	 * 新增数据
	 * @param confResourceWhitelist 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@SysLog("新增服务资源白名单配置表数据")
	@PostMapping("/save")
	public R<Boolean> save(@RequestBody ConfResourceWhitelist confResourceWhitelist) {
		return R.ok(confResourceWhitelistService.save(confResourceWhitelist));
	}

	/**
	 * 通过主键更新数据
	 * @param confResourceWhitelist 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@SysLog("更新服务资源白名单配置表数据")
	@PutMapping
	public R<Boolean> updateById(@RequestBody ConfResourceWhitelist confResourceWhitelist) {
		return R.ok(confResourceWhitelistService.updateById(confResourceWhitelist));
	}

	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@SysLog("删除服务资源白名单配置表数据")
	@DeleteMapping("/delete/{ids}")
	public R<Boolean> removeById(@PathVariable("ids") List<Integer> ids){
		return R.ok(confResourceWhitelistService.removeByIds(ids));
	}
}
